import cv2
import numpy as np


def access_pixels(img):
    height = img.shape[0]
    width = img.shape[1]
    channels = img.shape[2]
    print("height : %s , width : %s , channels : %s" % (height, width, channels))

    for row in range(height):
        for col in range(width):
            for c in range(channels):
                pv = img[row, col, c]
                img[row, col, c] = 255 - pv
    cv2.imshow('pixels', img)


def reverse_pixels(img):
    dst = cv2.bitwise_not(img)
    cv2.imshow('bitwise_not', dst)


def create_image():
    """
    #multi channels
    """
    img = np.zeros([300, 300, 3], np.uint8)
    img[:, :, 0] = np.ones([300, 300]) * 255
    cv2.imshow('create', img)
    cv2.waitKey(0)
    cv2.destroyWindow('create')

    '''
    #single channel
    
    img = np.zeros([300, 300, 1], np.uint8)
    img[:, :, 0] = np.ones([300, 300]) * 0
    cv2.imshow('create', img)
    cv2.waitKey(0)
    cv2.destroyWindow('create')
    '''


img = cv2.imread('lena.jpg', cv2.IMREAD_COLOR)
cv2.imshow('lena', img)
t1 = cv2.getTickCount()
# access_pixels(img)
reverse_pixels(img)
# create_image()
t2 = cv2.getTickCount()
time = (t2 - t1) / cv2.getTickFrequency()
print("use time %s s" % time)
cv2.waitKey(0)
cv2.destroyWindow('lena')
